package org.example.mytest.newControler;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.example.mytest.entity.User;
import org.example.mytest.mapper.UserMapper;
import org.example.mytest.newMapper.UsersMapper;
import org.example.mytest.newentity.users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
//分页查询 select * from ** limit 0,10
@RestController
@CrossOrigin

@RequestMapping("/myuser")
public class UserPageController {
    @Autowired
    UsersMapper usersMapper;
    UserMapper userMapper;
    @GetMapping("/findByPage")
    public IPage findByPage2(){
        //设置起始值及每页数
        Page<users> page = new Page<>(0,3);
        IPage iPage=usersMapper.selectPage(page,null);
        System.out.println(iPage);
        System.out.println("alksjdfalkfj");
        return iPage;
    }
    @GetMapping("/findByPage/{page}/{size}")
    public IPage findByPage(@PathVariable("page") Integer page,
                            @PathVariable("size") Integer size){
        //设置起始值及每页数
        Page<users> pages = new Page<>(page,size);
        IPage iPage=usersMapper.selectPage(pages,null);
        System.out.println(iPage);
        return iPage;
    }
    @PostMapping("/save")
    public int save(@RequestBody users users){

        int result = usersMapper.insert(users);
        return result;
    }
    @GetMapping("/selectById/{userId}")
    public users selectById(@PathVariable("userId")Integer userId)
    {
        return usersMapper.selectById(userId);
    }
    @PutMapping("/update2")
    public int update2(@RequestBody users uses){
        int result = usersMapper.updateById(uses);
        return result;
    }
    @DeleteMapping("/delete1/{userId}")
    public int delete1(@PathVariable("userId") Integer userId){
        int row=usersMapper.deleteById(userId);
        return row;
    }







}
